Learning Ratpack by Dan Woods

Learning Ratpack by Dan Woods

Author:Dan Woods
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2016-06-14T16:00:00+00:00


Here we use the StartEvent provided to the onStart method to get access to the server registry and resolve the Sql object.

This is the first introduction to working with the Sql DSL, and as you can see, the relatively simple execute call simply runs the provided SQL statement against the database.

From here on, we employ the sql.execute(..) call to bootstrap data directly into the TEST table.

The simplicity of working with databases through the Sql DSL is what makes it an appealing prospect for Groovy applications. It should be noted that the initialization that we are demonstrating in the Service is still performing blocking calls to the database. During the onStart call, it is not important that we schedule these calls to the blocking thread pool, because we will not be affecting request taking, as requests will not be accepted until all Service classes have been initialized.

When we plan to make database calls during request processing, however, we will want to ensure that blocking calls are scheduled to the blocking thread pool properly. As you are already aware of the Blocking fixture, you probably understand how we can use that within a handler to perform queries against the database. The updated code in Example 8-5 shows a get handler listing the values we have stored during initialization.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.